home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Demos / Stars8.s < prev    next >
Encoding:
Text File  |  1997-07-08  |  7.0 KB  |  305 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Name:      3D StarField 8
  3. ;Author:    Paul Manias
  4. ;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
  5. ;
  6. ;Same as the first starfield demo but runs in 8 colours.  Default is 500
  7. ;stars which runs fine on my A1200+Fast - but try 5000 stars or more for a
  8. ;real visual experience :-)
  9.  
  10.     INCDIR    "INCLUDES:"
  11.     INCLUDE    "games/games_lib.i"
  12.     INCLUDE    "games/games.i"
  13.  
  14. NSTARS    =    700    ;Number of stars
  15.  
  16. XSPEED    =    -4
  17. YSPEED    =    6
  18. ZSPEED    =    2
  19.  
  20. SCR_HEIGHT =    256
  21. SCR_WIDTH =    320
  22.  
  23.     SECTION    "Stars",CODE
  24.  
  25. ;==========================================================================;
  26. ;                             INITIALISE DEMO
  27. ;==========================================================================;
  28.  
  29.     STARTGMS
  30.  
  31. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  32.     move.l    GMSBase(pc),a6
  33.     lea    ScreenTags(pc),a0
  34.     CALL    ShowScreen
  35.     tst.l    d0
  36.     beq.s    .Error_Screen
  37.  
  38.     CALL    InitJoyPorts
  39.  
  40.     bsr.s    Main
  41.  
  42. .ReturnToDOS
  43.     move.l    GMSBase(pc),a6
  44.     move.l    Screen(pc),a0
  45.     CALL    DeleteScreen
  46. .Error_Screen
  47.     MOVEM.L    (SP)+,A0-A6/D1-D7
  48.     moveq    #ERR_OK,d0
  49.     rts
  50.  
  51. ;==========================================================================;
  52. ;
  53. ;==========================================================================;
  54.  
  55.     ;Randomize star coordinates
  56.  
  57. Main:    lea    StarCoords,a0    ;a0 = Ptr to star co-ordinates.
  58.     move.w    #NSTARS-1,d7
  59. .loop1    move.w    #8192,d1
  60.     CALL    SlowRandom
  61.     move.w    d0,(a0)+
  62.     CALL    SlowRandom
  63.     move.w    d0,(a0)+
  64.     CALL    SlowRandom
  65.     move.w    d0,(a0)+
  66.     dbra    d7,.loop1
  67.  
  68.     ;Construct perspective table
  69.  
  70.     lea    PersTable,a0    ;a0 = ptr to perspective table.
  71.     moveq    #0,d1    ;d1 = Starting at 0.
  72. .loop2    move.l    #$95FFFF,d2    ;d2 = $95FFFF
  73.     move.l    d1,d3    ;d3 = d1
  74.     add.w    #300,d3    ;d3 = ++300
  75.     divu    d3,d2    ;d2 = ($95ffff)/d3
  76.     move.w    d2,(a0)+    ;a0 = d2+
  77.     addq.w    #1,d1    ;d1 = ++1
  78.     cmp.w    #8192,d1    ;d1 = Equal to 8192?
  79.     bne.s    .loop2
  80.  
  81.     ;Construct plot tables for fast drawing.
  82.  
  83.     lea    PlotXTable,a0    ;a0 = X table - byte positions.
  84.     lea    PlotBTable,a1    ;a1 = Bit table (X related).
  85.     lea    PlotYTable,a2    ;a2 = Y table - line position.
  86.     moveq    #0,d0    ;d0 = 00
  87. .loop3    move.w    d0,d1    ;d1 = d0
  88.     lsr.w    #3,d1    ;d1 = (d0)<<3
  89.     move.w    d1,(a0)+    ;a0 = d1+
  90.  
  91.     move.w    d0,d1    ;d1 = d0
  92.     eor.w    #$FFFF,d1    ;d1 = (d0) eor $ffff
  93.     and.w    #%00000111,d1    ;d1 = &%00000111
  94.     move.w    d1,(a1)+    ;a1 = BitSet++
  95.  
  96.     cmp.w    #SCR_HEIGHT,d0    ;Write out the Y values for the
  97.     bge.s    .plot2    ;table.
  98.     move.w    d0,d1    ;d1 = Line Number.
  99.     mulu    #120,d1    ;d1 = (LineNumber)*80
  100.     move.w    d1,(a2)+    ;a2 = (LineNumber*80)++
  101.  
  102. .plot2    addq.w    #1,d0
  103.     cmp.w    #SCR_WIDTH,d0
  104.     bne.s    .loop3
  105.  
  106. ;==========================================================================;
  107. ;                                MAIN LOOP
  108. ;==========================================================================;
  109.  
  110. MainLoop:
  111.     move.l    GMSBase(pc),a6
  112.     move.l    Screen(pc),a0
  113.     CALL    WaitVBL
  114.     CALL    SwapBuffers
  115.  
  116. ;==========================================================================;
  117. ;                             STAR ANIMATION
  118. ;==========================================================================;
  119.  
  120.     movem.w    StarXPos(pc),d0/d1/d2    ;MV = d0/d1/d2 = XPos/YPos/ZPos
  121.     add.w    #XSPEED,d0    ;d0 = (StarXPos)+XSPEED
  122.     add.w    #YSPEED,d1    ;d1 = (StarYPos)+YSPEED
  123.     add.w    #ZSPEED,d2    ;d2 = (StarZPos)+ZSPEED
  124.     and.w    #%0000011111111111,d0
  125.     and.w    #%0000011111111111,d1
  126.     and.w    #%0000011111111111,d2
  127.     movem.w    d0/d1/d2,StarXPos
  128.  
  129.     lea    Sinus(pc),a0    ;a0 = Sinus table.
  130.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : X/Y/Z
  131.     add.w    (a0,d0.w),d3
  132.     add.w    (a0,d1.w),d4
  133.     add.w    (a0,d2.w),d5
  134.     movem.w    d3/d4/d5,StarXAdd
  135.  
  136. ;===========================================================================;
  137. ;                              SCREEN CLEAR
  138. ;===========================================================================;
  139. ;Let the blitter clear our 3rd screen while the CPU draws the stars.
  140.  
  141.     move.l    GMSBase(pc),a6
  142.     move.l    Screen(pc),a1    ;a1 = GameScreen
  143.     move.l    GS_Bitmap(a1),a0    ;a0 = Bitmap
  144.     move.l    GS_MemPtr3(a1),BMP_Data(a0)
  145.     CALL    ClearBitmap
  146.  
  147. ;==========================================================================;
  148. ;                               DRAW STARS
  149. ;==========================================================================;
  150.  
  151.     lea    StarCoords,a0    ;Draw starfield
  152.     lea    PersTable,a1    ;a1 = Perspective table.
  153.     lea    PlotXTable,a2    ;a2 = X table.
  154.     lea    PlotBTable,a3    ;a3 = Bit table.
  155.     lea    PlotYTable,a4    ;a4 = Y table.
  156.  
  157.     move.l    Screen(pc),a6
  158.     move.l    GS_MemPtr2(a6),a6
  159.  
  160.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : ?
  161.     add.w    #4096,d3    ;d3 = ++4096
  162.     add.w    #4096,d4    ;d4 = ++4096
  163.  
  164.     move.w    #NSTARS-1,d7
  165.  
  166. .draw    movem.w    (a0)+,d0/d1/d2    ;MV = d0/d1/d2 : XPos/YPos/ZPos.
  167.     add.w    d3,d0    ;Increase XPos.
  168.     and.w    #8191,d0    ;d0 = And'd
  169.     sub.w    #4096,d0    ;d0 = --4096
  170.  
  171.     add.w    d4,d1    ;Y-movement
  172.     and.w    #8191,d1    ;d1 = And'd
  173.     sub.w    #4096,d1    ;d1 = --4096
  174.  
  175.     add.w    d5,d2    ;Z-movement
  176.     and.w    #8191,d2
  177.     add.w    d2,d2    ;d2 = *2 [word]
  178.     move.w    (a1,d2.w),d6    ;d6 = Read from Perspective table.
  179.  
  180.     muls    d6,d0    ;X-projection
  181.     swap    d0
  182.     add.w    #176,d0
  183.  
  184.     cmp.w    #SCR_WIDTH-1,d0
  185.     bhi    .nodraw
  186.     muls    d6,d1    ;Y-projection
  187.     swap    d1
  188.     add.w    #136,d1
  189.     cmp.w    #SCR_HEIGHT-1,d1
  190.     bhi    .nodraw
  191.  
  192.     add.w    d0,d0    ;d0 = *2 [word]
  193.     add.w    d1,d1    ;d1 = *2 [word]
  194.     move.w    (a4,d1.w),d6    ;d6 = Plot Y.
  195.     add.w    (a2,d0.w),d6    ;d6 = ++PlotX.
  196.     move.w    (a3,d0.w),d0    ;d0 = BitValue.
  197.  
  198. .draw1    cmp.w    #4000,d2    ;Now draw the star according to
  199.     bgt.s    .draw2    ;its position in the Z axis.
  200.     bset    d0,(a6,d6.w)
  201.     dbra    d7,.draw
  202.     bra.s    .done
  203.  
  204. .draw2    cmp.w    #6000,d2
  205.     bgt.s    .draw3
  206.     bset    d0,40(a6,d6.w)
  207.     dbra    d7,.draw
  208.     bra.s    .done
  209.  
  210. .draw3    cmp.w    #8000,d2
  211.     bgt.s    .draw4
  212.     bset    d0,(a6,d6.w)
  213.     bset    d0,40(a6,d6.w)
  214.     dbra    d7,.draw
  215.     bra.s    .done
  216.  
  217. .draw4    cmp.w    #10000,d2
  218.     bgt.s    .draw5
  219.     bset    d0,80(a6,d6.w)
  220.     dbra    d7,.draw
  221.     bra.s    .done
  222.  
  223. .draw5    cmp.w    #12000,d2
  224.     bgt.s    .draw6
  225.     bset    d0,(a6,d6.w)
  226.     bset    d0,80(a6,d6.w)
  227.     dbra    d7,.draw
  228.     bra.s    .done
  229.  
  230. .draw6    cmp.w    #14000,d2
  231.     bgt.s    .draw7
  232.     bset    d0,40(a6,d6.w)
  233.     bset    d0,80(a6,d6.w)
  234.     dbra    d7,.draw
  235.     bra.s    .done
  236.  
  237. .draw7    bset    d0,(a6,d6.w)
  238.     bset    d0,40(a6,d6.w)
  239.     bset    d0,80(a6,d6.w)
  240. .nodraw    dbra    d7,.draw
  241.  
  242. .done    move.l    GMSBase(pc),a6
  243.     moveq    #JPORT1,d0    ;Read from port 1 (mouse).
  244.     moveq    #JT_ZBXY,d1
  245.     CALL    ReadJoyPort    ;Go get port status.
  246.     btst    #MB_LMB,d0
  247.     beq    MainLoop
  248.     rts
  249.  
  250. ;===========================================================================;
  251. ;                                  DATA
  252. ;===========================================================================;
  253.  
  254. ScreenTags:
  255.     dc.l    TAGS_GAMESCREEN
  256. Screen:    dc.l    0
  257.     dc.l    GSA_Palette,.palette
  258.     dc.l    GSA_ScrWidth,320
  259.     dc.l    GSA_ScrHeight,256
  260.     dc.l    GSA_Planes,3
  261.     dc.l    GSA_Attrib,TPLBUFFER
  262.     dc.l    GSA_ScrMode,LORES
  263.     dc.l    GSA_ScrType,ILBM
  264.     dc.l    TAGEND
  265.  
  266. .palette
  267.     dc.l    $000000,$f0f0f0,$c0c0c0,$909090 ;%000, %100, %010, %110
  268.     dc.l    $707070,$505050,$303030,$101010 ;%001, %101, %011, %111
  269.  
  270. ;===========================================================================;
  271. ;                                STAR DATA
  272. ;===========================================================================;
  273.  
  274. StarXAdd
  275.     dc.w    33    ;Star stuff
  276. StarYAdd
  277.     dc.w    12
  278. StarZAdd
  279.     dc.w    -114
  280.  
  281. StarXPos
  282.     dc.w    0    ;Sinus positions
  283. StarYPos
  284.     dc.w    310
  285. StarZPos
  286.     dc.w    1280
  287.  
  288.     INCLUDE    "GMS:source/asm/demos/StarSinus.i"
  289.  
  290.     SECTION    Storage,BSS
  291.  
  292. StarCoords
  293.     ds.w    NSTARS*3    ;Star coordinates
  294.  
  295. PersTable
  296.     ds.w    8192    ;Perspective table
  297.  
  298. PlotXTable
  299.     ds.w    SCR_WIDTH    ;Plot tables
  300. PlotBTable
  301.     ds.w    SCR_WIDTH
  302. PlotYTable
  303.     ds.w    SCR_HEIGHT
  304.  
  305.